package com.cangsan.erhai.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cangsan.erhai.common.PageBean;
import com.cangsan.erhai.common.R;
import com.cangsan.erhai.entity.TabVipGoods;
import com.cangsan.erhai.service.TabVipGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/vip/goods")
public class TabVipGoodsController {
    @Autowired
    private TabVipGoodsService tabVipGoodsService;

    @PostMapping("/list")
    public R list(@RequestBody PageBean pageBean){
        QueryWrapper<TabVipGoods> queryWrapper = new QueryWrapper<>();
        Page<TabVipGoods> page = new Page<>(pageBean.getPageNum(), pageBean.getPageSize());
        Page<TabVipGoods> pageResult = tabVipGoodsService.page(page,queryWrapper);
        Map<String,Object> result = new HashMap<>();
        List<TabVipGoods> records = pageResult.getRecords();
        result.put("dataList",records);
        result.put("total",pageResult.getTotal());
        return R.ok(result);
    }

    @PostMapping("/saveOrUpdate")
    public R saveOrUpdate(@RequestBody TabVipGoods TabVipGoods){
        tabVipGoodsService.saveOrUpdate(TabVipGoods);
        return R.ok();
    }

    @GetMapping("/{id}")
    public R delete(@PathVariable Long id) {
        tabVipGoodsService.removeById(id);
        return R.ok("删除成功");
    }

}
